What are AngularJS modules?
193
19-Jun-2024
Updated on 19-Jun-2024
Ashutosh Kumar Verma
19-Jun-2024AngularJS modules
A module in AngularJS is a basic organizational unit that helps organize and organize an application into smaller reusable objects. Here is a detailed description focusing only on modules in AngularJS:
Definition and Creation
definition-
In AngularJS, modules are created using the angular.module function. This function takes the module name as the first parameter and an optional array of dependencies (other modules or services) as the second parameter.
In the above syntax
Here '
myApp
' is the name of the module, and[]
means that 'myApp
' has no dependencies on other modules. If it had dependencies, they will be listed in the array.Main Module-
Typically, an AngularJS application starts with a core module that acts as the core of the application. This main module can depend on other modules and can define top-level configuration, routing, and initialization logic.
Dependencies-
Modules can depend on other modules. When a module depends on another module, it can use components (such as controllers, services, filters, etc.) defined in the dependent module.
above example-
Here '
myApp
' depends on 'dependencyModule
', which enables 'myApp
' to use the objects defined in 'dependencyModule
'.Components of Modules
Here are some component of angular js modules as follow,
Controllers
Controllers are functions that handle business logic, user interaction, and state management in a module.
Services
Services are single objects or functions that perform specific tasks, such as retrieving data, performing calculations, or interacting with external systems.
Directives
Directives are markers on a DOM element (such as attributes, element names, comments, or CSS classes) that extend HTML with new behavior.
Filters
Filters format the value of an expression for display to the user.
There are many built-in modules used in Angular.js programs.
Also, Read: What are directives in AngularJS?